<template>
  <div class="box">
    <h1>B组件,{{ count.gold }}</h1>
    <el-button type="primary" size="default" @click="handleAdd">
      加入购物车
    </el-button>
  </div>
</template>

<script setup>
import { useCount } from "../../store/count";
import { useCart } from "../../store/cart";
const count = useCount();
const cart = useCart();
const handleAdd = () => {
  let goodsObj = {
    name: "新商品",
    price: (Math.random() * 600 + 400).toFixed(2),
    n: 1,
  };
  cart.cartAdd(goodsObj);
};
</script>

<style lang="scss" scoped>
.box {
  height: 400px;
  border: 1px solid #333;
  width: 50%;
}
</style>
